<template>
  <view class="page">
    <view class="content bg" v-if="!isShowResult">
      <view class="tips" @click="uploadFile()">
        <view>拍照批改</view><text>作业一拍，秒出解析</text>
      </view>
    </view>
    <view class="content" v-else>
      <view class="box">
        <view class="box_title"> 我的试卷 </view>
        <view class="box_content">
          <view class="box_section">
            <image :src="paperUrl" mode="widthFix" />
          </view>
        </view>
      </view>
      <view class="box">
        <view class="box_title"> 试卷解析 </view>
        <view class="box_content">
          <view class="box_section">
            <zero-markdown-view :markdown="resultStr"></zero-markdown-view>
          </view>
          <view class="box_btn">
            <view class="box_icon" @click="back()">
              <image src="https://hengxiao-resource.oss-cn-hangzhou.aliyuncs.com/web/resources/images/hengxiao/ai/icon1.png" mode="scaleToFill" />
              <text>返回</text>
            </view>
            <view class="box_icon" @click="uploadFile()">
              <image src="https://hengxiao-resource.oss-cn-hangzhou.aliyuncs.com/web/resources/images/hengxiao/ai/icon1.png" mode="scaleToFill" />
              <text>再拍一题</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      isShowResult: false,
      paperUrl: "",
      resultStr: "",
    };
  },
  onLoad() {},
  methods: {
    uploadFile() {
      uni.chooseImage({
        // 从本地相册选择图片或使用相机拍照。
        count: 1, //默认选择1张图片
        sizeType: ["original", "compressed"], //original 原图，compressed 压缩图，默认二者都有
        success: (response) => {
          //成功则返回图片的本地文件路径列表 tempFilePaths
          this.paperUrl = response.tempFilePaths[0];
          this.$upload(this.paperUrl, null, "/admin/util/aiAnswer").then(
            (res) => {
              this.resultStr = res.data;
              this.isShowResult = true;
            }
          );
        },
      });
    },
    back() {
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./ai";
</style>
